﻿package de.gameduell.framework.util {

	/**
	 * A very simple lock manager that processes lock requests.
	 */
	public class LockManager {
		
		private static var instance:LockManager = new LockManager();
		private var lockList:Array;

		/**
		 * Returns the initilized LockManager object.
		 */
		public static function getInstance():LockManager {
			return instance;
		}

		/**
		 * Singleton constructor - don't call it directly.
		 */
		public function LockManager() {
			if(instance){
				throw new Error("LockManager::LockManager: Singleton and can only be accessed through Singleton.getInstance()"); 
			}
			lockList = new Array();
		}

		/**
		 * Puts an object into the locklist and hold it until it's released by calling unlock.
		 * 
		 * @param object	object to lock
		 */
		public function lock(object:Object):void {
			while(lockList[object]){ /*supress empty statement waring*/ };
			lockList[object] = true;
		}

		/**
		 * Removes an object from the list of locked items.
		 * 
		 * @param object	object to unlock
		 */
		public function unlock(object:Object):void {
			lockList[object] = false;
		}
	}
}
